package cn.bellychang.leetcode.question141;

import java.util.HashSet;

/**
 * @author ChangLiang
 * @date 2021/3/8
 */
public class Solution3 {

    public boolean hasCycle(ListNode head) {
        boolean result = false;
        HashSet<ListNode> set = new HashSet();
        while(head!=null){
            if(set.contains(head)){
                result = true;
                break;
            }
            set.add(head);
            head = head.next;
        }
        return result;
    }
}
